# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=p11-kit

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.20.1
pkgrel=1
pkgdesc="Library to work with PKCS#11 modules"
arch=(i686 x86_64)
url="http://p11-glue.freedesktop.org"
license=('BSD')
depends=("${MINGW_PACKAGE_PREFIX}-libtasn1" "${MINGW_PACKAGE_PREFIX}-libffi" "${MINGW_PACKAGE_PREFIX}-gettext")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=($url/releases/$_realname-$pkgver.tar.gz{,.sig}
    p11-kit-0.20.1-getuid.patch
    0000-no-proxy.mingw.patch
    0001-fix-gtkdoc.all.patch)
md5sums=('88c651137f76a167336639371eafd8cc'
         'SKIP'
         '163f463a5ab7611790ecdeb42c39be6f'
         '411a2c8c553d961a9a1ae7507b952d22'
         'b573ff16048f807a7310a6e893e1b2ce')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/p11-kit-0.20.1-getuid.patch
  patch -p1 -i ${srcdir}/0000-no-proxy.mingw.patch
  patch -p1 -i ${srcdir}/0001-fix-gtkdoc.all.patch
  
  autoreconf -fi
}

build() {
    mkdir -p "${srcdir}/${_realname}-${pkgver}-build-${CARCH}"
    cd "${srcdir}/${_realname}-${pkgver}-build-${CARCH}"
    "${srcdir}"/${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
       --disable-trust-module
    make
  #make -C trust asn || make -j1 -C trust asn
  #make || make -j1
}

package() {
    cd "${srcdir}/${_realname}-${pkgver}-build-${CARCH}"
    make -j1 DESTDIR="$pkgdir" install
    # find "${pkgdir}${MINGW_PREFIX}" -name '*.exe' | xargs -rtl1 rm
    # find "${pkgdir}${MINGW_PREFIX}" -name '*.dll' | xargs -rtl1 ${_arch}-strip --strip-unneeded
    # find "${pkgdir}${MINGW_PREFIX}" -name '*.a' -o -name '*.dll' | xargs -rtl1 ${_arch}-strip -g
    #rm -r "${pkgdir}${MINGW_PREFIX}/share"
}
